package com.uenpay.im.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aswife.ui.MaskImageView;
import com.qyx.android.entity.GroupMemberEntity;
import com.qyx.android.message.type.PacketType;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;

import java.util.ArrayList;

/**
 * 群成员
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class GroupMemberAdapter extends BaseAdapter {

	private ArrayList<GroupMemberEntity> mArrayList;
	private LayoutInflater _mlLayoutInflater;

	public GroupMemberAdapter(Context mContext,
			ArrayList<GroupMemberEntity> mArrayList) {
		_mlLayoutInflater = LayoutInflater.from(mContext);
		this.mArrayList = mArrayList;
	}

	@Override
	public int getCount() {
		return mArrayList.size();
	}

	@Override
	public GroupMemberEntity getItem(int position) {
		return mArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final GroupMember gm;
		if (convertView == null) {
			gm = new GroupMember();
			convertView = _mlLayoutInflater.inflate(R.layout.item_group_member,
					parent,false);

			gm.member_avatar = (MaskImageView) convertView
					.findViewById(R.id.group_member_avatar);
			gm.member_name = (TextView) convertView
					.findViewById(R.id.group_member_name);

			convertView.setTag(gm);
		} else {
			gm = (GroupMember) convertView.getTag();
		}
		GroupMemberEntity mGroupMemberEntity = getItem(position);
		gm.member_name.setText(mGroupMemberEntity.nick_name);
		gm.member_avatar.SetUrl(APIConfiguration.getAvatarUrlNormal(
				mGroupMemberEntity.cust_id + "", PacketType.PERSONAL));

		return convertView;
	}

	class GroupMember {
		private MaskImageView member_avatar;
		private TextView member_name;
	}

}
